Using Gateways with HTTP Bridge
When you use a gateway with the HTTP bridge, you must bind the devices to the gateway. Before you begin, read Using the HTTP bridge for general information on using the HTTP bridge with OmniCore.
To use gateways with the HTTP bridge:
- Create and configure the gateway, if you haven't already.
- Create devices, if you haven't already.
- Bind the devices to the gateway.
- Use the gateway to publish telemetry events and update a device's configuration.
Publishing the device's telemetry events through the gateway
After you've bound the device to the gateway, use the publishEvent method to publish telemetry events on behalf of the device to OmniCore. Binary payload data must be base64-encoded.
Using the gateway's JWT:
curl -X POST -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"binaryData": "DATA", "gatewayInfo": {"delegatedDeviceId: "device-id"}}' -H 'cache-control: no-cache' 'https://demo-http.api.cloud.korewireless.com/http/subscriptions/{subscription-id}/registries/{registry-id}/devices/{gateway-id}/publishEvent'
Telemetry events are forwarded to a Cloud Pub/Sub topic, as specified in console or with the eventNotificationConfigs[i].pubsubTopicName field in the device registry resource. The publishEvent method provides an optional subFolder field for classifying telemetry events. To learn how to publish data from subfolders to separate Pub/Sub topics, see using the HTTP bridge.
Updating device configuration through the gateway
Gateways must explicitly request new configurations for the devices attached to it when using the HTTP bridge.
To get the device configuration that's currently available from OmniCore, use a getConfig request. You can include the JWT from either the gateway or the device in the authorization bearer header.
Using the gateway's JWT:
curl -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"binaryData": "DATA", "gatewayInfo": {"delegatedDeviceId: "device-id"}}' -H 'cache-control: no-cache' 'https://demo-http.api.cloud.korewireless.com/http/subscriptions/{subscription-id}/registries/{registry-id}/devices/{gateway-id}/config?localVersion={version}&gatewayInfo={"delegatedDeviceId: "device-id"}'
Setting device state through the gateway
Use a setState request to report device state to OmniCore. State data must be base64-encoded. You can include the JWT from the gateway in the authorization bearer header.
Using the gateway's JWT:
curl -X POST -H 'authorization: Bearer GATEWAY_JWT' -H 'content-type: application/json' --data '{"state": {"binaryData": "DATA"}, "gatewayInfo": {"delegatedDeviceId: "device-id"}}' -H 'cache-control: no-cache' 'https://demo-http.api.cloud.korewireless.com/http/subscriptions/{subscription-id}/registries/{registry-id}/devices/{gateway-id}/setState'
Getting device state data
To retrieve device state data, view the device details in OmniCore console or use the API. For more details, see Getting device state data.